
function Content(id, title, date, image, type, name, status, collect) {
	this.id = id;
	this.title = title;
	this.date = date;
	this.image = image;
	this.type = type;
	this.name = name;
	this.status = status;// status_yes --- not completed status_no --- completed
	this.collect = collect;
}

Content.prototype.toHTML = function() {
	var contentHTML = "";

	if (this.image) {
		contentHTML += "<div class='textTag' id='"
				+ this.id
				+ "'>"
				+ "<div class='personPhoto'><img src='"
				+ this.image
				+ "'/></div>"
				+ "<div class='personNameLabel'><span id='personNameLabel'>姓名：</span></div>"
				+ "<div class='personName'><span id='personName'>"
				+ this.name
				+ "</span></div>"
				+ "<div class='titleLabel'><span id='titleLabel'>标题：</span></div>"
				+ "<div class='title'><span id='title'>"
				+ this.title
				+ "</span></div>"
				+ "<div class='timeLabel'><span id='timeLabel'>时间：</span></div>"
				+ "<div class='time'><span id='time'>"
				+ this.date
				+ "</span></div>"
				+ "<div class='"
				+ this.status
				+ "'><span id='status'></span></div>"
				+ "<div><span id='collectButton' class='"
				+ this.collect
				+ "' onclick='collectButtonClicked();'></span></div>"
				+ "<div class='mainReply'><span id='mainReply' onclick='openContentPage(event);'></span></div>"
				+ "</div>";
	} else {
		contentHTML += "<div class='textTag' id='"
				+ this.id
				+ "'>"
				+ "<div class='personPhoto'><img src='#'/></div>"
				+ "<div class='personNameLabel'><span id='personNameLabel'>姓名：</span></div>"
				+ "<div class='personName'><span id='personName'>"
				+ this.name
				+ "</span></div>"
				+ "<div class='titleLabel'><span id='titleLabel'>标题：</span></div>"
				+ "<div class='title'><span id='title'>"
				+ this.title
				+ "</span></div>"
				+ "<div class='timeLabel'><span id='timeLabel'>时间：</span></div>"
				+ "<div class='time'><span id='time'>"
				+ this.date
				+ "</span></div>"
				+ "<div class='"
				+ this.status
				+ "'><span id='status'></span></div>"
				+ "<div><span id='collectButton' class='"
				+ this.collect
				+ "' onclick='collectButtonClicked();'></span></div>"
				+ "<div class='mainReply'><span id='mainReply' onclick='openContentPage(event);'></span></div>"
				+ "</div>";
	}
	return contentHTML;
};

Content.prototype.containsText = function(text) {
	return (this.title.toLowerCase().indexOf(text.toLowerCase()) != -1);
};



var content = new Array();

var ajaxReq = new AjaxRequest();

function loadContent() {
	document.getElementById("content").innerHTML = "<img src='wait.gif'  id='waitImage' alt='Loading...' />";
	// ajaxReq.send("GET", "xxx.xml", handleRequest);
	//ajaxReq.send("POST", "PostContent", handleRequest);
	sendXMLPost("PostContent","<username>"+getUserName()+"</username>",handleRequest);
}

function handleRequest(responseXML) {
	//if (ajaxReq.getReadyState() == 4 && ajaxReq.getStatus() == 200) {
		var xmlData = responseXML.getElementsByTagName("content")[0];

		var entries = xmlData.getElementsByTagName("entry");
		for ( var i = 0; i < entries.length; i++) {
			content.push(new Content(
					getText(entries[i].getElementsByTagName("id")[0]), 
					getText(entries[i].getElementsByTagName("title")[0]),
					getText(entries[i].getElementsByTagName("date")[0]),
					getText(entries[i].getElementsByTagName("image")[0]),
					getText(entries[i].getElementsByTagName("type")[0]),
					getText(entries[i].getElementsByTagName("author")[0]),
					getText(entries[i].getElementsByTagName("status")[0]),
					getText(entries[i].getElementsByTagName("collect")[0])));
			if (content[i].type == "course") {
				allCourseContentCounts++;
			} else if (content[i].type == "activity") {
				allActivityContentCounts++;
			} else if (content[i].type == "life") {
				allLifeContentCounts++;
			} else if (content[i].type == "find") {
				allFindContentCounts++;
			} else if (content[i].type == "another") {
				allAnotherContentCounts++;
			}
			allContentCounts++;
		}

		if (allContentCounts == 0) {
			allPageCounts = 0;
		} else {
			if (parseInt(allContentCounts % 4) == 0) {
				allPageCounts = parseInt(allContentCounts / 4);
			} else {
				allPageCounts = parseInt(allContentCounts / 4) + 1;
			}
		}

		// alert(allContentCounts);
		// alert(allCourseContentCounts);
		// alert(allActivityContentCounts);
		// alert(allLifeContentCounts);
		// alert(allFindContentCounts);
		// alert(allAnotherContentCounts);

		if (allCourseContentCounts == 0) {
			allCoursePageCounts = 0;
		} else {
			if (parseInt(allCourseContentCounts % 4) == 0) {
				allCoursePageCounts = parseInt(allCourseContentCounts / 4);
			} else {
				allCoursePageCounts = parseInt(allCourseContentCounts / 4) + 1;
			}
		}

		if (allActivityContentCounts == 0) {
			allActivityPageCounts = 0;
		} else {
			if (parseInt(allActivityContentCounts % 4) == 0) {
				allActivityPageCounts = parseInt(allActivityContentCounts / 4);
			} else {
				allActivityPageCounts = parseInt(allActivityContentCounts / 4) + 1;
			}
		}

		if (allLifeContentCounts == 0) {
			allLifePageCounts = 0;
		} else {
			if (parseInt(allLifeContentCounts % 4) == 0) {
				allLifePageCounts = parseInt(allLifeContentCounts / 4);
			} else {
				allLifePageCounts = parseInt(allLifeContentCounts / 4) + 1;
			}
		}

		if (allFindContentCounts == 0) {
			allFindPageCounts = 0;
		} else {
			if (parseInt(allFindContentCounts % 4) == 0) {
				allFindPageCounts = parseInt(allFindContentCounts / 4);
			} else {
				allFindPageCounts = parseInt(allFindContentCounts / 4) + 1;
			}
		}

		if (allAnotherContentCounts == 0) {
			allAnotherPageCounts = 0;
		} else {
			if (parseInt(allAnotherContentCounts % 4) == 0) {
				allAnotherPageCounts = parseInt(allAnotherContentCounts / 4);
			} else {
				allAnotherPageCounts = parseInt(allAnotherContentCounts / 4) + 1;
			}
		}

		// alert(allPageCounts);
		// alert(allCoursePageCounts);
		// alert(allActivityPageCounts);
		// alert(allLifePageCounts);
		// alert(allFindPageCounts);
		// alert(allAnotherPageCounts);
		setUserName();

		isFirst = true;
		showContent(0, "all", 1, "content");
	//}
}

function setUserName() {
	var cookies = document.cookie.split("; ");
	for ( var i = 0; i < cookies.length; i++) {
		if (cookies[i].split("=")[0] == "username") {
			var username = cookies[i].split("=")[1];
			document.getElementById("welcomeText").innerHTML = "欢迎回来，"
					+ username;
			break;
		}
	}
}

var tagContent = new Array();

function showContent(numEntries, type, pageNumber, array) {
	if (array == "content") {
		tagContent.length = 0;
		currentPage = pageNumber;

		
		if (numEntries == 0) {
			numEntries = content.length;
		}
		if (type == "all") {
			var node = document.getElementById("content");
			while (node.firstChild) {
				node.removeChild(node.firstChild);
			}
			var i = 0;
			while (i < content.length && i < numEntries) {
				tagContent.push(content[i]);
				i++;

			}
			;
			var k = 0, contentListHTML = "";
			while (k < tagContent.length) {
				if (k >= (pageNumber - 1) * 4 && k < pageNumber * 4) {
					contentListHTML += tagContent[k].toHTML();
				}
				k++;
			}
			var node = document.getElementById("lastPage2");
			while (node.firstChild) {
				node.removeChild(node.firstChild);
			}
			document.getElementById("lastPage2").innerHTML = allPageCounts;

			// addPages(allContentCounts, allPageCounts);
			// ///////////////////////////////////////////////////////
		} else if (type == "course") {
			var node = document.getElementById("content");
			while (node.firstChild) {
				node.removeChild(node.firstChild);
			}
			var i = 0;
			while (i < content.length && i < numEntries) {
				if (content[i].type == "course") {
					tagContent.push(content[i]);
				}
				i++;
			}
			;
			var k = 0, contentListHTML = "";
			while (k < tagContent.length) {
				if (k >= (pageNumber - 1) * 4 && k < pageNumber * 4) {
					contentListHTML += tagContent[k].toHTML();
				}
				k++;
			}
			var node = document.getElementById("lastPage2");
			while (node.firstChild) {
				node.removeChild(node.firstChild);
			}
			document.getElementById("lastPage2").innerHTML = allCoursePageCounts;

			// addPages(allCourseContentCounts, allCoursePageCounts);
			// //////////////////////////////////////////////////////
		} else if (type == "activity") {
			var node = document.getElementById("content");
			while (node.firstChild) {
				node.removeChild(node.firstChild);
			}
			var i = 0;
			while (i < content.length && i < numEntries) {
				if (content[i].type == "activity") {
					tagContent.push(content[i]);
				}
				i++;

			}
			;
			var k = 0, contentListHTML = "";
			while (k < tagContent.length) {
				if (k >= (pageNumber - 1) * 4 && k < pageNumber * 4) {
					contentListHTML += tagContent[k].toHTML();
				}
				k++;
			}
			var node = document.getElementById("lastPage2");
			while (node.firstChild) {
				node.removeChild(node.firstChild);
			}
			document.getElementById("lastPage2").innerHTML = allActivityPageCounts;

			// addPages(allActivityContentCounts, allActivityPageCounts);
			// //////////////////////////////////////////////////
		} else if (type == "life") {
			var node = document.getElementById("life");
			while (node.firstChild) {
				node.removeChild(node.firstChild);
			}
			var i = 0;
			while (i < content.length && i < numEntries) {
				if (content[i].type == "life") {
					tagContent.push(content[i]);
				}
				i++;

			}
			;
			var k = 0, contentListHTML = "";
			while (k < tagContent.length) {
				if (k >= (pageNumber - 1) * 4 && k < pageNumber * 4) {
					contentListHTML += tagContent[k].toHTML();
				}
				k++;
			}
			var node = document.getElementById("lastPage2");
			while (node.firstChild) {
				node.removeChild(node.firstChild);
			}
			document.getElementById("lastPage2").innerHTML = allLifePageCounts;

			// addPages(allLifeContentCounts, allLifePageCounts);
			// ////////////////////////////////////////////////////
		} else if (type == "find") {
			var node = document.getElementById("find");
			while (node.firstChild) {
				node.removeChild(node.firstChild);
			}
			var i = 0;
			while (i < content.length && i < numEntries) {
				if (content[i].type == "find") {
					tagContent.push(content[i]);
				}
				i++;

			}
			;
			var k = 0, contentListHTML = "";
			while (k < tagContent.length) {
				if (k >= (pageNumber - 1) * 4 && k < pageNumber * 4) {
					contentListHTML += tagContent[k].toHTML();
				}
				k++;
			}
			var node = document.getElementById("lastPage2");
			while (node.firstChild) {
				node.removeChild(node.firstChild);
			}
			document.getElementById("lastPage2").innerHTML = allFindPageCounts;

			// addPages(allFindContentCounts, allFindPageCounts);
			// ////////////////////////////////////////////////////
		} else if (type == "another") {
			var node = document.getElementById("another");
			while (node.firstChild) {
				node.removeChild(node.firstChild);
			}
			var i = 0;
			while (i < content.length && i < numEntries) {
				if (content[i].type == "another") {
					tagContent.push(content[i]);
				}
				i++;

			}
			;
			var k = 0, contentListHTML = "";
			while (k < tagContent.length) {
				if (k >= (pageNumber - 1) * 4 && k < pageNumber * 4) {
					contentListHTML += tagContent[k].toHTML();
				}
				k++;
			}
			var node = document.getElementById("lastPage2");
			while (node.firstChild) {
				node.removeChild(node.firstChild);
			}
			document.getElementById("lastPage2").innerHTML = allAnotherPageCounts;

			// addPages(tagContent.length, lengthToPage(tagContent.length));

		} else {
			alert("对不起，找不到您要找的内容！");
		}
		if (isFirst) {
			addPages(tagContent.length, lengthToPage(tagContent.length));
			var number = parseInt(pageNumber % 6);
			setPage(pageNumber);
		}
		document.getElementById("content").innerHTML = decodeURIComponent(contentListHTML);
		// var number = parseInt(pageNumber%6);
		// setPage(number);

		// //////////////////////////////////////////////////////
		// //////////////////////////////////////////////////////
	} else {
		currentPage = pageNumber;
		
		
		
		if (numEntries == 0) {
			numEntries = searchContent.length;
		}
		var node = document.getElementById("content");
		while (node.firstChild) {
			node.removeChild(node.firstChild);
		}
		var k = 0, searchContentListHTML = "";
		while (k < searchContent.length) {
			if (k >= (pageNumber - 1) * 4 && k < pageNumber * 4) {
				searchContentListHTML += searchContent[k].toHTML();
			}
			k++;
		}
		node = document.getElementById("lastPage2");
		while (node.firstChild) {
			node.removeChild(node.firstChild);
		}
		document.getElementById("lastPage2").innerHTML = searchPageCounts;

		// /////////////////////////////////////////////////
		/*
		 * else if(type == "course"){ var node =
		 * document.getElementById("content"); while(node.firstChild){
		 * node.removeChild(node.firstChild); } var k = 0, contentListHTML = "";
		 * while(k < searchContent.length){ if(k >= (pageNumber-1)*4 && k <
		 * pageNumber*4){ contentListHTML += searchContent[k].toHTML(); } k++; }
		 * var node = document.getElementById("lastPage2");
		 * while(node.firstChild){ node.removeChild(node.firstChild); }
		 * document.getElementById("lastPage2").innerHTML =
		 * allAnotherPageCounts;
		 * /////////////////////////////////////////////////// }else if(type ==
		 * "activity"){ var node = document.getElementById("activity");
		 * while(node.firstChild){ node.removeChild(node.firstChild); } var k =
		 * 0, contentListHTML = ""; while(k < searchContent.length){ if(k >=
		 * (pageNumber-1)*4 && k < pageNumber*4){ contentListHTML +=
		 * searchContent[k].toHTML(); } k++; }
		 * /////////////////////////////////////////////////// }else if(type ==
		 * "life"){ var node = document.getElementById("life");
		 * while(node.firstChild){ node.removeChild(node.firstChild); } var k =
		 * 0, contentListHTML = ""; while(k < searchContent.length){ if(k >=
		 * (pageNumber-1)*4 && k < pageNumber*4){ contentListHTML +=
		 * searchContent[k].toHTML(); } k++; }
		 * ///////////////////////////////////////////////////// }else if(type ==
		 * "find"){ var node = document.getElementById("find");
		 * while(node.firstChild){ node.removeChild(node.firstChild); } var k =
		 * 0, contentListHTML = ""; while(k < searchContent.length){ if(k >=
		 * (pageNumber-1)*4 && k < pageNumber*4){ contentListHTML +=
		 * searchContent[k].toHTML(); } k++; }
		 * ////////////////////////////////////////////////////// }else if(type ==
		 * "another"){ var node = document.getElementById("another");
		 * while(node.firstChild){ node.removeChild(node.firstChild); } var k =
		 * 0, contentListHTML = ""; while(k < searchContent.length){ if(k >=
		 * (pageNumber-1)*4 && k < pageNumber*4){ contentListHTML +=
		 * searchContent[k].toHTML(); } k++; }
		 * //////////////////////////////////////////////////// }else{
		 * alert("对不起，找不到您要找的内容！"); }
		 */
		if (isFirst) {

			addPages(searchContent.length, lengthToPage(searchContent.length));
			// var number = parseInt(pageNumber%6);
			setPage(pageNumber);
		}
		document.getElementById("content").innerHTML = decodeURIComponent(searchContentListHTML);

	}
}

var searchContent = new Array();
var isFirst = true;

function searchContentShow(flag) {
	searchContent.length = 0;

	var searchText = document.getElementById("searchtext").value;
	if (searchText == "" || !searchText) {
		searchOrTag = "tag";
		isFirst = true;
		showContent(0, flag, 1, "content");
		return;
	}

	for ( var i = 0; i < content.length; i++) {
		if (content[i].type == flag) {
			if (content[i].containsText(searchText)) {
				searchContent.push(new Content(
						content[i].id, 
						content[i].title,
						content[i].date,
						content[i].image,
						content[i].type,
						content[i].name,
						content[i].status,
						content[i].collect));
				searchContentCounts++;
			}

			if (searchContentCounts == 0) {
				searchPageCounts = 0;
			} else {
				if (parseInt(searchContentCounts % 4) == 0) {
					searchPageCounts = parseInt(searchContentCounts / 4);
				} else {
					searchPageCounts = parseInt(searchContentCounts / 4) + 1;
				}
			}
		}
	}
	if (searchContent.length == 0) {
		alert("对不起，没有找到您要找的内容！");
		return;
	}
	isFirst = true;
	showContent(0, flag, 1, "searchContent");

}

function randomContent() {
	var i = Math.floor(Math.random() * content.length);
	alert(content[i]);
}

function getText(elem) {
	var text = "";
	if (elem) {
		if (elem.childNodes) {
			for ( var i = 0; i < elem.childNodes.length; i++) {
				var child = elem.childNodes[i];
				if (child.nodeValue) {
					text += child.nodeValue;
				} else {
					if (child.childNodes[0]) {
						if (child.childNodes[0].nodeValue) {
							text += child.childNodes[0].nodeValue;
						}
					}
				}
			}
		}
	}
	return text;
}

var typeFlag = "all";

function logOut() {
	window.location.href = "index.html";
}

function courseTagClicked() {
	isFirst = true;
	searchOrTag = "tag";
	showContent(0, "course", 1, "content");
	focusCourseTag();

}

function focusCourseTag() {
	document.getElementById("courseTag").className = "courseChecked";
	document.getElementById("lifeTag").className = "lifeNormal";
	document.getElementById("activityTag").className = "activityNormal";
	document.getElementById("findTag").className = "findNormal";
	document.getElementById("anotherTag").className = "anotherNormal";
	document.getElementById("allTag").className = "allNormal";
	typeFlag = "course";
}

function lifeTagClicked() {
	isFirst = true;
	searchOrTag = "tag";
	showContent(0, "life", 1, "content");
	focusLifeTag();

}

function focusLifeTag() {
	document.getElementById("courseTag").className = "courseNormal";
	document.getElementById("lifeTag").className = "lifeChecked";
	document.getElementById("activityTag").className = "activityNormal";
	document.getElementById("findTag").className = "findNormal";
	document.getElementById("anotherTag").className = "anotherNormal";
	document.getElementById("allTag").className = "allNormal";
	typeFlag = "life";
}

function activityTagClicked() {
	isFirst = true;
	searchOrTag = "tag";
	showContent(0, "activity", 1, "content");
	focusActivityTag();

}

function focusActivityTag() {
	document.getElementById("courseTag").className = "courseNormal";
	document.getElementById("lifeTag").className = "lifeNormal";
	document.getElementById("activityTag").className = "activityChecked";
	document.getElementById("findTag").className = "findNormal";
	document.getElementById("anotherTag").className = "anotherNormal";
	document.getElementById("allTag").className = "allNormal";
	typeFlag = "activity";
}

function findTagClicked() {
	isFirst = true;
	searchOrTag = "tag";
	showContent(0, "find", 1, "content");
	focusFindTag();

}

function focusFindTag() {
	document.getElementById("courseTag").className = "courseNormal";
	document.getElementById("lifeTag").className = "lifeNormal";
	document.getElementById("activityTag").className = "activityNormal";
	document.getElementById("findTag").className = "findChecked";
	document.getElementById("anotherTag").className = "anotherNormal";
	document.getElementById("allTag").className = "allNormal";
	typeFlag = "find";
}

function anotherTagClicked() {
	isFirst = true;
	searchOrTag = "tag";
	showContent(0, "another", 1, "content");
	focusAnotherTag();

}

function focusAnotherTag() {
	document.getElementById("courseTag").className = "courseNormal";
	document.getElementById("lifeTag").className = "lifeNormal";
	document.getElementById("activityTag").className = "activityNormal";
	document.getElementById("findTag").className = "findNormal";
	document.getElementById("anotherTag").className = "anotherChecked";
	document.getElementById("allTag").className = "allNormal";
	typeFlag = "another";
}

function allTagClicked() {
	isFirst = true;
	searchOrTag = "tag";
	showContent(0, "all", 1, "content");
	focusAllTag();
}

function focusAllTag() {
	document.getElementById("courseTag").className = "courseNormal";
	document.getElementById("lifeTag").className = "lifeNormal";
	document.getElementById("activityTag").className = "activityNormal";
	document.getElementById("findTag").className = "findNormal";
	document.getElementById("anotherTag").className = "anotherNormal";
	document.getElementById("allTag").className = "allChecked";
	typeFlag = "all";
}

var searchOrTag = "tag";
var allPageCounts = 0;
var searchPageCounts = 0;
var allContentCounts = 0;
var searchContentCounts = 0;

var allCourseContentCounts = 0;
var allActivityContentCounts = 0;
var allFindContentCounts = 0;
var allAnotherContentCounts = 0;
var allLifeContentCounts = 0;

var allCoursePageCounts = 0;
var allActivityPageCounts = 0;
var allFindPageCounts = 0;
var allAnotherPageCounts = 0;
var allLifePageCounts = 0;

function changePage(flag) {
	var pageID = setPage(flag);
	var pageNumber = parseInt(document.getElementById(pageID).firstChild.nodeValue);

	currentPage = pageNumber;
	isFirst = false;
	if (searchOrTag == "tag") {
		showContent(0, typeFlag, pageNumber, "content");
	} else {
		showContent(0, searchFlag, pageNumber, "searchContent");
	}
}

function setPage(flag) {
	var pageID;
	if (flag == 1 || flag == "1") {
		pageID = "pageNumber1";
		if (document.getElementById("page1")) {
			document.getElementById("page1").className = "page1_checked";
		}
		if (document.getElementById("page2")) {
			document.getElementById("page2").className = "page2_normal";
		}
		if (document.getElementById("page3")) {
			document.getElementById("page3").className = "page3_normal";
		}
		if (document.getElementById("page4")) {
			document.getElementById("page4").className = "page4_normal";
		}
		if (document.getElementById("page5")) {
			document.getElementById("page5").className = "page5_normal";
		}
		if (document.getElementById("page6")) {
			document.getElementById("page6").className = "page6_normal";
		}
	} else if (flag == 2 || flag == "2") {
		pageID = "pageNumber2";
		if (document.getElementById("page1")) {
			document.getElementById("page1").className = "page1_normal";
		}
		if (document.getElementById("page2")) {
			document.getElementById("page2").className = "page2_checked";
		}
		if (document.getElementById("page3")) {
			document.getElementById("page3").className = "page3_normal";
		}
		if (document.getElementById("page4")) {
			document.getElementById("page4").className = "page4_normal";
		}
		if (document.getElementById("page5")) {
			document.getElementById("page5").className = "page5_normal";
		}
		if (document.getElementById("page6")) {
			document.getElementById("page6").className = "page6_normal";
		}
	} else if (flag == 3 || flag == "3") {
		pageID = "pageNumber3";
		if (document.getElementById("page1")) {
			document.getElementById("page1").className = "page1_normal";
		}
		if (document.getElementById("page2")) {
			document.getElementById("page2").className = "page2_normal";
		}
		if (document.getElementById("page3")) {
			document.getElementById("page3").className = "page3_checked";
		}
		if (document.getElementById("page4")) {
			document.getElementById("page4").className = "page4_normal";
		}
		if (document.getElementById("page5")) {
			document.getElementById("page5").className = "page5_normal";
		}
		if (document.getElementById("page6")) {
			document.getElementById("page6").className = "page6_normal";
		}
	} else if (flag == 4 || flag == "4") {
		pageID = "pageNumber4";
		if (document.getElementById("page1")) {
			document.getElementById("page1").className = "page1_normal";
		}
		if (document.getElementById("page2")) {
			document.getElementById("page2").className = "page2_normal";
		}
		if (document.getElementById("page3")) {
			document.getElementById("page3").className = "page3_normal";
		}
		if (document.getElementById("page4")) {
			document.getElementById("page4").className = "page4_checked";
		}
		if (document.getElementById("page5")) {
			document.getElementById("page5").className = "page5_normal";
		}
		if (document.getElementById("page6")) {
			document.getElementById("page6").className = "page6_normal";
		}
	} else if (flag == 5 || flag == "5") {
		pageID = "pageNumber5";
		if (document.getElementById("page1")) {
			document.getElementById("page1").className = "page1_normal";
		}
		if (document.getElementById("page2")) {
			document.getElementById("page2").className = "page2_normal";
		}
		if (document.getElementById("page3")) {
			document.getElementById("page3").className = "page3_normal";
		}
		if (document.getElementById("page4")) {
			document.getElementById("page4").className = "page4_normal";
		}
		if (document.getElementById("page5")) {
			document.getElementById("page5").className = "page5_checked";
		}
		if (document.getElementById("page6")) {
			document.getElementById("page6").className = "page6_normal";
		}
	} else if (flag == 6 || flag == "6") {
		pageID = "pageNumber6";
		if (document.getElementById("page1")) {
			document.getElementById("page1").className = "page1_normal";
		}
		if (document.getElementById("page2")) {
			document.getElementById("page2").className = "page2_normal";
		}
		if (document.getElementById("page3")) {
			document.getElementById("page3").className = "page3_normal";
		}
		if (document.getElementById("page4")) {
			document.getElementById("page4").className = "page4_normal";
		}
		if (document.getElementById("page5")) {
			document.getElementById("page5").className = "page5_normal";
		}
		if (document.getElementById("page6")) {
			document.getElementById("page6").className = "page6_checked";
		}
	} else if (flag == 7 || flag == "7") {
		changePage(5);
		nextPage();
	} else if (flag == 0 || flag == "0") {
		if (document.getElementById("page2")) {
			changePage(2);
		} else {
			return;
		}
		frontPage();
	} else {
		return;
	}
	return pageID;

}

var searchFlag = "course";

function courseSearchClicked() {
	document.getElementById("course").className = "courseSearchChecked";
	document.getElementById("life").className = "lifeSearchNormal";
	document.getElementById("activity").className = "activitySearchNormal";
	document.getElementById("find").className = "findSearchNormal";
	document.getElementById("another").className = "anotherSearchNormal";
	searchFlag = "course";
}

function lifeSearchClicked() {
	document.getElementById("course").className = "courseSearchNormal";
	document.getElementById("life").className = "lifeSearchChecked";
	document.getElementById("activity").className = "activitySearchNormal";
	document.getElementById("find").className = "findSearchNormal";
	document.getElementById("another").className = "anotherSearchNormal";
	searchFlag = "life";
}

function activitySearchClicked() {
	document.getElementById("course").className = "courseSearchNormal";
	document.getElementById("life").className = "lifeSearchNormal";
	document.getElementById("activity").className = "activitySearchChecked";
	document.getElementById("find").className = "findSearchNormal";
	document.getElementById("another").className = "anotherSearchNormal";
	searchFlag = "activity";
}

function findSearchClicked() {
	document.getElementById("course").className = "courseSearchNormal";
	document.getElementById("life").className = "lifeSearchNormal";
	document.getElementById("activity").className = "activitySearchNormal";
	document.getElementById("find").className = "findSearchChecked";
	document.getElementById("another").className = "anotherSearchNormal";
	searchFlag = "find";
}

function anotherSearchClicked() {
	document.getElementById("course").className = "courseSearchNormal";
	document.getElementById("life").className = "lifeSearchNormal";
	document.getElementById("activity").className = "activitySearchNormal";
	document.getElementById("find").className = "findSearchNormal";
	document.getElementById("another").className = "anotherSearchChecked";
	searchFlag = "another";
}

function searchButtonClicked() {
	if (searchFlag == "course") {
		focusCourseTag();
	} else if (searchFlag == "life") {
		focusLifeTag();
	} else if (searchFlag == "activity") {
		focusActivityTag();
	} else if (searchFlag == "find") {
		focusFindTag();
	} else if (searchFlag == "another") {
		focusAnotherTag();
	}
	searchOrTag = "search";
	//alert("searchFlag");
	searchContentShow(searchFlag);
}

function openPersonPage() {
	window.open("personPage.html", "_blank");
}

function openContentPage() {
	document.cookie = "taskId = " + event.srcElement.parentElement.parentElement.id;
	window.open("contentPage.html","_blank");
}

function firstPage() {
	var lastPage;
	if (searchOrTag == "tag") {
		lastPage = lengthToPage(tagContent.length);
	} else {
		lastPage = lengthToPage(searchContent.length);
	}
	for (i = 0; i < lastPage; i++) {
		frontPage();
	}
}

function lastPage() {
	var lastPage;
	if (searchOrTag == "tag") {
		lastPage = lengthToPage(tagContent.length);
	} else {
		lastPage = lengthToPage(searchContent.length);
	}
	var i = 0;
	for (i = 0; i < lastPage; i++) {
		nextPage();
	}

}

var currentPage = 1;

function frontPage() {
	var i = 0;
	if (tagContent.length == 0 && searchContent == 0) {
		return;
	}
	if (parseInt(document.getElementById("pageNumber1").firstChild.nodeValue) == currentPage) {
		if (currentPage == 1) {
			return;
		} else {
			alert("!");
		}
	} else if (parseInt(document.getElementById("pageNumber2").firstChild.nodeValue) == currentPage) {
		changePage(1);
		if (currentPage == 1) {
			return;

		} else {
			moveRightPageNumber();
		}
	} else if (parseInt(document.getElementById("pageNumber3").firstChild.nodeValue) == currentPage) {
		changePage(2);
	} else if (parseInt(document.getElementById("pageNumber4").firstChild.nodeValue) == currentPage) {
		changePage(3);
	} else if (parseInt(document.getElementById("pageNumber5").firstChild.nodeValue) == currentPage) {
		changePage(4);
	} else if (parseInt(document.getElementById("pageNumber6").firstChild.nodeValue) == currentPage) {
		changePage(5);
	}
}

function nextPage() {
	var lastPage;
	if (searchOrTag == "tag") {
		lastPage = lengthToPage(tagContent.length);
	} else {
		lastPage = lengthToPage(searchContent.length);
	}

	if (document.getElementById("pageNumber6")
			&& parseInt(document.getElementById("pageNumber6").firstChild.nodeValue) == currentPage) {
		if (currentPage == lastPage) {

			return;
		} else {
			alert("!");
		}
	} else if (document.getElementById("pageNumber5")
			&& parseInt(document.getElementById("pageNumber5").firstChild.nodeValue) == currentPage) {
		if (currentPage == lastPage) {
			return;
		}
		changePage(6);
		if (currentPage == lastPage) {
			return;
		} else {
			moveLeftPageNumber();
		}
	} else if (document.getElementById("pageNumber4")
			&& parseInt(document.getElementById("pageNumber4").firstChild.nodeValue) == currentPage) {
		if (currentPage == lastPage) {
			return;
		}
		changePage(5);
	} else if (document.getElementById("pageNumber3")
			&& parseInt(document.getElementById("pageNumber3").firstChild.nodeValue) == currentPage) {
		if (currentPage == lastPage) {
			return;
		}
		changePage(4);
	} else if (document.getElementById("pageNumber2")
			&& parseInt(document.getElementById("pageNumber2").firstChild.nodeValue) == currentPage) {
		if (currentPage == lastPage) {
			return;
		}
		changePage(3);
	} else if (document.getElementById("pageNumber1")
			&& parseInt(document.getElementById("pageNumber1").firstChild.nodeValue) == currentPage) {
		if (currentPage == lastPage) {
			return;
		}
		changePage(2);
	}
}

function addPages(contentCounts, pageCounts) {
	var node = document.getElementById("Pages");
	while (node.firstChild) {
		node.removeChild(node.firstChild);
	}

	var num;
	var pageCountArray = new Array();

	for (num = 1; num <= contentCounts; num++) {
		pageCountArray.push(num);
	}
	if (pageCounts >= 6) {
		node.innerHTML += "<span class='page6_normal' id='page6' onclick='changePage(7);'><font id='pageNumber6'>"
				+ 6 + "</font></span>";
		node.innerHTML += "<span class='page5_normal' id='page5' onclick='changePage(5);'><font id='pageNumber5'>"
				+ 5 + "</font></span>";
		node.innerHTML += "<span class='page4_normal' id='page4' onclick='changePage(4);'><font id='pageNumber4'>"
				+ 4 + "</font></span>";
		node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>"
				+ 3 + "</font></span>";
		node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>"
				+ 2 + "</font></span>";
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>"
				+ 1 + "</font></span>";
	} else if (pageCounts == 5) {
		node.innerHTML += "<span class='page5_normal' id='page5' onclick='changePage(5);'><font id='pageNumber5'>"
				+ 5 + "</font></span>";
		node.innerHTML += "<span class='page4_normal' id='page4' onclick='changePage(4);'><font id='pageNumber4'>"
				+ 4 + "</font></span>";
		node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>"
				+ 3 + "</font></span>";
		node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>"
				+ 2 + "</font></span>";
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>"
				+ 1 + "</font></span>";
	} else if (pageCounts == 4) {
		node.innerHTML += "<span class='page4_normal' id='page4' onclick='changePage(4);'><font id='pageNumber4'>"
				+ 4 + "</font></span>";
		node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>"
				+ 3 + "</font></span>";
		node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>"
				+ 2 + "</font></span>";
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>"
				+ 1 + "</font></span>";
	} else if (pageCounts == 3) {
		node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>"
				+ 3 + "</font></span>";
		node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>"
				+ 2 + "</font></span>";
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>"
				+ 1 + "</font></span>";
	} else if (pageCounts == 2) {
		//node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>"
		//		+ 3 + "</font></span>";
		node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>"
				+ 2 + "</font></span>";
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>"
				+ 1 + "</font></span>";
	} else if (pageCounts == 1) {
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>"
				+ 1 + "</font></span>";
	} else {
		alert("No contents");
	}
}

function lengthToPage(length) {
	var page;
	if (length == 0) {
		page = 0;
	} else {
		if (parseInt(length % 4) == 0) {
			page = parseInt(length / 4);
		} else {
			page = parseInt(length / 4) + 1;
		}
	}
	return page;
}

function moveLeftPageNumber() {
	var node = document.getElementById("Pages");
	while (node.firstChild) {
		node.removeChild(node.firstChild);
	}
	var num6 = currentPage + 1;
	var num5 = currentPage;
	var num4 = currentPage - 1;
	var num3 = currentPage - 2;
	var num2 = currentPage - 3;
	var num1 = currentPage - 4;

	node.innerHTML += "<span class='page6_normal' id='page6' onclick='changePage(7);'><font id='pageNumber6'>"
			+ num6 + "</font></span>";
	node.innerHTML += "<span class='page5_normal' id='page5' onclick='changePage(5);'><font id='pageNumber5'>"
			+ num5 + "</font></span>";
	node.innerHTML += "<span class='page4_normal' id='page4' onclick='changePage(4);'><font id='pageNumber4'>"
			+ num4 + "</font></span>";
	node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>"
			+ num3 + "</font></span>";
	node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>"
			+ num2 + "</font></span>";
	node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>"
			+ num1 + "</font></span>";
	// alert("currenPage "+ currentPage);
	changePage(5);
}

function moveRightPageNumber() {
	var node = document.getElementById("Pages");
	while (node.firstChild) {
		node.removeChild(node.firstChild);
	}

	var num6 = currentPage + 4;
	var num5 = currentPage + 3;
	var num4 = currentPage + 2;
	var num3 = currentPage + 1;
	var num2 = currentPage;
	var num1 = currentPage - 1;

	node.innerHTML += "<span class='page6_normal' id='page6' onclick='changePage(7);'><font id='pageNumber6'>"
			+ num6 + "</font></span>";
	node.innerHTML += "<span class='page5_normal' id='page5' onclick='changePage(5);'><font id='pageNumber5'>"
			+ num5 + "</font></span>";
	node.innerHTML += "<span class='page4_normal' id='page4' onclick='changePage(4);'><font id='pageNumber4'>"
			+ num4 + "</font></span>";
	node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>"
			+ num3 + "</font></span>";
	node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>"
			+ num2 + "</font></span>";
	node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>"
			+ num1 + "</font></span>";
	changePage(2);
}

function goButtonClicked() {
	if (!document.getElementById("pageSelect").value
			|| document.getElementById("pageSelect").value == 0) {
		alert("请输入正确的页数");
	} else {
		var i;
		var gap = parseInt(document.getElementById("pageSelect").value)
				- currentPage;
		if (parseInt(document.getElementById("pageSelect").value) > currentPage) {
			for (i = 0; i < gap; i++) {
				nextPage();
			}
		} else {
			for (i = 0; i < -gap; i++) {
				frontPage();
			}
		}
	}
}

function collectButtonClicked() {
	var arguments = "<collect>";
	arguments = addTag(arguments, "username", getUserName());
	arguments = addTag(arguments, "id",
			event.srcElement.parentElement.parentElement.id);

	if (window.event.srcElement.className == "collectButton_no") {
		window.event.srcElement.className = "collectButton_yes";

		arguments = addTag(arguments, "isCollected", "yes");

	} else {
		window.event.srcElement.className = "collectButton_no";
		// arguments = addTag(arguments, "id",
		// event.srcElement.parentElement.parentElement.id);
		arguments = addTag(arguments, "isCollected", "no");
	}
	arguments += "</collect>";
	sendXMLPost("SetCollect", arguments, null);

}

function iwant() {
	window.open("addTask.html", "_blank");
}

